package com.mym.demo;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/10 17:17
 * @description
 */
public class Graphic {


    public double getArea() {
        return 0;
    }

    public double getPerimeter() {
        return 0;
    }

    public String getInfo() {
        return null;
    }
}

class Circle extends Graphic {
    private double r;

    public Circle() {
    }

    public Circle(double r) {
        this.r = r;
    }

    public double getR() {
        return r;
    }

    public void setR(double r) {
        this.r = r;
    }

    @Override
    public double getArea() {

        return Math.PI * r * r;
    }

    @Override
    public double getPerimeter() {
        return 2 * r * Math.PI;
    }

    @Override
    public String getInfo() {
        return "圆的面积：" + getArea() + "，圆的周长" + getPerimeter();
    }
}

class Rectangle extends Graphic {
    private double a;
    private double b;

    public Rectangle() {
    }

    public Rectangle(double a, double b) {
        this.a = a;
        this.b = b;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    @Override
    public double getArea() {
        return a * b;
    }

    @Override
    public double getPerimeter() {
        return 2 * a + 2 * b;
    }

    @Override
    public String getInfo() {
        return "矩形的面积：" + getArea() + "，矩形的周长" + getPerimeter();
    }
}
class Triangle extends Graphic{
    private double a;
    private double b;
    private double c;

    public Triangle() {
    }

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }

    @Override
    public double getArea() {
        double p = (a + b + c)/2;
        return Math.sqrt(p * (p-a) * (p-b) * (p-c));
    }

    @Override
    public double getPerimeter() {
        return a+b+c;
    }

    @Override
    public String getInfo() {
        return "三角形的面积：" + getArea() + "，三角形的周长" + getPerimeter();
    }


}



